package com.gjy.datetime.time;

import org.junit.jupiter.api.Test;

import java.text.SimpleDateFormat;
import java.time.Clock;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.TimeZone;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-03-31 10:58:48
 */
public class ClockTest {

    @Test
    public void test4() {
        TimeZone zone = TimeZone.getDefault();
        System.out.println("zone.getID() = " + zone.getID());
    }

    @Test
    public void test3() {
        LocalDate now = LocalDate.now(Clock.systemDefaultZone());
        LocalDate of = LocalDate.of(2023, 3, 31);
        System.out.println("of.isBefore(now) = " + of.isBefore(now));
        System.out.println("of.isEqual(now) = " + of.isEqual(now));
    }

    @Test
    public void test2() {
        ZoneId zone = Clock.systemDefaultZone().getZone();
        System.out.println("zone = " + zone);
    }

    @Test
    public void test1() {
//        Clock clock = Clock.systemDefaultZone();
        Clock clock = Clock.systemUTC();
        long millis = clock.millis();
        System.out.println("millis = " + millis);
        parse(millis);
    }

    private static void parse(long millis) {
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(new Date(millis));
        System.out.println("format = " + format);
    }
}
